<?php include_once $_SERVER['DOCUMENT_ROOT']."/config.php" ; ?>



<?php
    //用ai创建文件，并且入库记录


//Our Wedding Crafts: Tailored to Perfection for Weddings, Meetings, and Events!
//We support customization services, offer creative designs, and provide unbeatable affordability for all your special occasions.
//
//【Recommended Products】
//+Acrylic Invitation
//+Sealing Wax Stamp
//+Invitation Box
//+Wedding Planner
//
//WhatsApp: +86 13535350765
//Email: mail@circledesign.cn;
//
//#WeddingInvitationDesign
//#HandmadeWaxSeals
//#ModernInvitations
//#IntimateWedding

    //收集数据，整理成content
    $content =
        "Our Wedding Crafts: Tailored to Perfection for Weddings, Meetings, and Events!<br/><br/>
         We support customization services, offer creative designs, and provide unbeatable affordability for all your special occasions.";

    $content .= "参考上面的内容，生成一个全新的文案,是英文的";
    $content .= "结果只返回的结果，不要解释，不要返回其他内容，不要返回其他结果，不要返回其他说明，不要返回其他提示；";




    $url = 'https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions';

// 若没有配置环境变量，请用百炼API Key将下行替换为：$apiKey = "sk-xxx";
#$apiKey = getenv('DASHSCOPE_API_KEY');
    $apiKey =  "sk-6b9ebd5e8e5d406d8e0e69ec16ea3766";


// 设置请求头
    $headers = [
        'Authorization: Bearer '.$apiKey,
        'Content-Type: application/json'
    ];
// 设置请求体
    $para_data = [
        // 模型列表：https://help.aliyun.com/zh/model-studio/getting-started/models
        //"model" => "qwen-plus",
        //"model" => "qwen-max",
        "model" => "qwen-turbo",
        "messages" => [
            [
                "role" => "system",
                "content" => "You are a facebook post assistant."
            ],
            [
                "role" => "user",
                "content" => $content
            ]
        ]
    ];
// 初始化cURL会话
    $ch = curl_init();
// 设置cURL选项
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($para_data));
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);//返回不输出结果
// 执行cURL会话
    $response = curl_exec($ch);
// 检查是否有错误发生
    if (curl_errno($ch)) {
        echo 'Curl error: ' . curl_error($ch);
    }
// 关闭cURL资源
    curl_close($ch);
// 输出响应结果



    $_result = json_decode($response, true);
    $_result=$_result['choices'][0]['message']['content'];


    $_data['ai_content']=$_result;

$_data['ai_content']=$_data['ai_content'].
"<br/><br/>【Recommended Products】
<br/>+Acrylic Invitation
<br/>+Sealing Wax Stamp
<br/>+Invitation Box
<br/>+Wedding Planner
<br/>
<br/>WhatsApp: +86 13535350765
<br/>Email: mail@circledesign.cn
";


//读取数据库中 content_creator_subdata 中 随机一个 content_creator_data_nid =2 的内容，用原生语句去写
$sql="SELECT * FROM ".$table_prefix."content_creator_subdata WHERE  content_creator_data_nid =22 ORDER BY RAND() LIMIT 1";
$query = mysql_query($sql) or die ("error:".mysql_error());

while($row = mysql_fetch_array($query))
{
    $tag=$row;
}


echo $_data['ai_content']=$_data['ai_content']."<br/><br/>".$tag['content'];




    //插入数据到数据库 content_creator_subdata
    $sql=insert_data($table_prefix.'content_creator_subdata',$_data);
    $query = mysql_query($sql) or die ("error:".mysql_error());


    //写个js ，自动刷新,刷新次数可以自定义。用变量counts控制
    echo "<script>
    var counts = 0;
    function refreshPage() {
        if (counts < 30) {
            window.location.reload();
            counts++;
            setTimeout(refreshPage, 1000);
        }
    }
    refreshPage();
</script>";
